import cache from '@/utils/cache'
import constant from '@/utils/constant'
import axios from 'axios'
import { ElMessage } from 'element-plus'

// 文件导出
export const useLogLoginExportApi = (dataForm: any) => {
	let urlExport = constant.apiUrl + 'sys/log/login/export?accessToken=' + cache.getToken()

	console.log('打印这个地址', urlExport)
	axios({
		url: urlExport,
		method: 'GET',
		responseType: 'blob'
	}).then(res => {
		const down = document.createElement('a')
		// 文件名没传，则使用时间戳
		down.download = '登录日志表' + new Date().getTime().toString() || new Date().getTime().toString()
		// 隐藏a标签
		down.style.display = 'none'

		// 创建下载url
		let binaryData = []
		binaryData.push(res.data)
		down.href = URL.createObjectURL(new Blob(binaryData, { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }))

		// 模拟点击下载
		document.body.appendChild(down)
		down.click()

		// 释放URL
		URL.revokeObjectURL(down.href)
		// 下载完成移除
		document.body.removeChild(down)
		ElMessage.success('下载成功')
	})
}
export const useLogOprateExportApi = (dataForm: any) => {
	let urlExport = constant.apiUrl + 'sys/log/operate/export?accessToken=' + cache.getToken()

	console.log('打印这个地址', urlExport)
	axios({
		url: urlExport,
		method: 'GET',
		responseType: 'blob'
	}).then(res => {
		const down = document.createElement('a')
		// 文件名没传，则使用时间戳
		down.download = '操作日志表' + new Date().getTime().toString() || new Date().getTime().toString()
		// 隐藏a标签
		down.style.display = 'none'

		// 创建下载url
		let binaryData = []
		binaryData.push(res.data)
		down.href = URL.createObjectURL(new Blob(binaryData, { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }))

		// 模拟点击下载
		document.body.appendChild(down)
		down.click()

		// 释放URL
		URL.revokeObjectURL(down.href)
		// 下载完成移除
		document.body.removeChild(down)
		ElMessage.success('下载成功')
	})
}
